using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using TowerNames = Enums.TowerNames;

public class TowerManager
{
    #region INSTANCE
    private static TowerManager m_instance;
    public static TowerManager Instance
    {
        get
        {
            if (m_instance == null)
            {
                m_instance = new TowerManager();
            }

            return m_instance;
        }
    }
    private TowerManager() { }
    #endregion

    private Dictionary<TowerNames, List<GameObject>> m_towers;
    private GameObject m_towerHierarchy;
    //private GameObject m_LaserTowers;

    public void Initialize( )
    {
        m_towers = new Dictionary<TowerNames, List<GameObject>>();
        m_towerHierarchy = new GameObject("Tower List");
    }


    public void AddTower(TowerNames name, GameObject tower)
    {
        if (m_towers.ContainsKey(name))
        {
            tower.transform.parent = m_towerHierarchy.transform;
            m_towers[name].Add(tower);
            return;
        }

        tower.transform.parent = m_towerHierarchy.transform;
        m_towers.Add(name, new List<GameObject> { tower });
    }
    public void RemoveTower(TowerNames name, GameObject tower)
    {
        if (m_towers.ContainsKey(name))
        {
            List<GameObject> towers = m_towers[name];
            foreach (GameObject obj in towers)
            {
                if (tower == obj)
                {
                    m_towers[name].Remove(obj);
                    return;
                }
            }
        }
    }
    public void RemoveTowers(TowerNames name)
    {
        if (m_towers.ContainsKey(name))
        {
            m_towers.Remove(name);
        }
    }
    public void VaildTowerLocation(Vector3 point, float radius)
    {

    }
}
